import React from 'react';
import FlatButton from 'material-ui/FlatButton';
import LoginDialog from './MyLoginDialog';
import RegisterDialog from './MyRegisterDialog';

export default class ActionsNoLogin extends React.Component {
    constructor(props) {
        super(props)

        this.state = {
            loginDialogOpen: false,
            registerDialogOpen: false,
        }

        this.handleCloseLogin = this.handleCloseLogin.bind(this)
        this.handleOpenLogin = this.handleOpenLogin.bind(this)
        this.handleCloseRegister = this.handleCloseRegister.bind(this)
        this.handleOpenRegister = this.handleOpenRegister.bind(this)
        this.loginSuccess = this.loginSuccess.bind(this)
    }

    handleOpenLogin() {
        this.setState({
            loginDialogOpen: true,
        })
    }

    handleOpenRegister() {
        this.setState({
            registerDialogOpen: true,
        })
    }

    handleCloseLogin() {
        this.setState({
            loginDialogOpen: false,
        })
    }

    handleCloseRegister() {
        this.setState({
            registerDialogOpen: false,
        })
    }

    loginSuccess(user){
        console.info('ActionsNoLogin :: loginSuccess()')
        this.props.login(user)
    }

    render() {
        return (
            <div>
                <FlatButton style={{color: 'white'}} onClick={this.handleOpenLogin} label="登录"/>
                <FlatButton style={{color: 'white'}} onClick={this.handleOpenRegister} label="Register"/>

                <LoginDialog open={this.state.loginDialogOpen} handleClose={this.handleCloseLogin} login={this.loginSuccess} />
                <RegisterDialog open={this.state.registerDialogOpen} handleClose={this.handleCloseRegister} />
            </div>
        )
    }
}
